using System.Linq;
using System.Collections.Generic;

namespace Citi.Scheduler.Domain
{
    public partial class Category
    {
        public IEnumerable<Category> GetAllChildren()
        {
            var categories = new List<Category> { this };

            foreach (var child in Children)
                categories.AddRange(child.GetAllChildren());

            return categories;
        }

        public IEnumerable<Category> GetCategoriesByLibraryType(LibraryType libraryType)
        {
            return SelectAll<Category>().Where(x => x.Routines.Any(y => y.LibraryVersion.Type == (int)libraryType));
        }
    }
}
